<?php
//require_once 'CoreReportingApiReference.php';
$profileId=$_SESSION['profileid'];
$startDate;
$endDate;
function getRows($results, $table) {
    $table;

    if (count($results->getRows()) > 0) {
      $table .= '<table border="1" cellspacing="1" cellpadding="5">';

      // Print headers.
      $table .= '<tr>';

      foreach ($results->getColumnHeaders() as $header) {
        $table .= '<th>' . $header->name . '</th>';
      }
      $table .= '</tr>';

      // Print table rows.
      foreach ($results->getRows() as $row) {
	 
        $table .= '<tr>';
          foreach ($row as $cell) {
            $table .= '<td>'
                   . htmlspecialchars($cell, ENT_NOQUOTES)
                   . '</td>';
          }
        $table .= '</tr>';
      }
      $table .= '</table>';

    } else {
      $table .= '<p>No results found.</p>';
    }

    return $table;
  }
 function getRow($results, $table, $th1, $th2) {
$table;

if (count($results->getRows()) > 0) {
  $table .= '<table border="1" cellspacing="1" cellpadding="5">';


  $table .= '<tr>';

	$table .= '<th>'.$th1.'</th>';
	$table .= '<th>'.$th2.'</th>';

  $table .= '</tr>';
  foreach ($results->getRows() as $row) {
 
	$table .= '<tr>';
	$table .= '<td align="left">'
                      .$row[0].
                    '</td>';
			$table .= '<td align="right">'
                      .$row[1]. 
                    '</td>';
	$table .= '</tr>';
  }
  $table .= '</table>';

} else {
  $table .= '<p>No results found.</p>';
}

    return $table;
  }
?>

<div class = "row" >
<?php
$PVParams = array(
      'dimensions' => 'ga:date',
      
      
      'max-results' => '25');
$resultsPV = $analytics->data_ga->get(
       'ga:' . $profileId,
       '2014-11-01',
       '2014-11-15',
	   'ga:pageviews',
       $PVParams
	   );


//return $table;

$th1 = "Tanggal";
$th2 = "Jumlah Halaman Yang dilihat User";
$table = "Page Impression";
$demo = getRow($resultsPV, $table, $th1, $th2);
print $demo; 
	   
?>

</div>
<div class = "row" >
<?php
//echo "<h3>top pages requested</h3>";
$PPParams = array(
      'dimensions' => 'ga:pagePath',
      
      
      'max-results' => '25');
$resultsPP = $analytics->data_ga->get(
       'ga:' . $profileId,
       '2014-11-01',
       '2014-11-15',
	   'ga:pageviews',
       $PPParams
	   );
	   
//$demo = getRows($resultsPP);
//print $demo;
$th1 = "URL Halaman";
$th2 = "Jumlah Halaman Yang dilihat User";
$table = "Top Pages Requested";
$demo = getRow($resultsPP, $table, $th1, $th2);
print $demo;
	   
?>
</div>

<div class = "row" >
<?php
echo "<h3>peak activity</h3>";
$SHParams = array(
      'dimensions' => 'ga:hour',
      
      'sort' => '-ga:sessions',
      'max-results' => '25');
$resultsSH = $analytics->data_ga->get(
       'ga:' . $profileId,
       '2014-11-01',
       '2014-11-15',
	   'ga:sessions',
       $SHParams
	   );
	   
//$demo = getRows($resultsSH);
//print $demo;

$th1 = "Jam";
$th2 = "Jumlah Kunjungan ke Website";
$table = "Peak Activity";
$demo = getRow($resultsSH, $table, $th1, $th2);
print $demo;	   


?>
</div>

<div class = "row" >
<?php
//echo "<h3>hits</h3>";
$HParams = array(
      'dimensions' => 'ga:dimension1',
      
      'sort' => '-ga:hits',
		);
$resultsH = $analytics->data_ga->get(
       'ga:' . $profileId,
       '2014-11-01',
       '2014-11-15',
	   'ga:hits',
       $HParams
	   );
	   
//$demo = getRows($resultsH);
//print $demo;

$th1 = "ID Audience";
$th2 = "Jumlah klik yang dilakukan";
$table = "Hits";
$demo = getRow($resultsH, $table, $th1, $th2);
print $demo;	   


?>
</div>

<div class = "row" >
<?php
//echo "<h3>visits</h3>";
$VParams = array(
      'dimensions' => 'ga:dimension1',
      
      'sort' => '-ga:sessions',
		);
$resultsV = $analytics->data_ga->get(
       'ga:' . $profileId,
       '2014-11-01',
       '2014-11-15',
	   'ga:sessions',
       $VParams
	   );
	   
//$demo = getRows($resultsV);
//print $demo;
	   
$th1 = "ID Audience";
$th2 = "Jumlah kunjungan yang dilakukan";
$table = "Visits";
$demo = getRow($resultsV, $table, $th1, $th2);
print $demo;	   

?>
</div>

<div class = "row" >
<?php
//echo "<h3>unique visitors</h3>";
$UVParams = array(
      'dimensions' => 'ga:date',
      
      
		);
$resultsUV = $analytics->data_ga->get(
       'ga:' . $profileId,
       '2014-11-01',
       '2014-11-15',
	   'ga:newUsers',
       $UVParams
	   );
	   
//$demo = getRows($resultsUV);
//print $demo;
	   
$th1 = "Tanggal";
$th2 = "Jumlah pengunjung baru";
$th2 = "Jumlah pengunjung baru";
$table = "Unique Visitors";
$demo = getRow($resultsUV, $table, $th1, $th2, $th3);
print $demo;

?>
</div>

<div class = "row" >
<?php

$ADParams = array(
      'dimensions' => 'ga:adGroup',
      
      
		);
$resultsAD = $analytics->data_ga->get(
       'ga:' . $profileId,
       '2014-12-06',
       '2014-12-21',
	   'ga:impressions',
       $ADParams
	   );
	   
$th1 = "Nama Grup Iklan";
$th2 = "Jumlah Audience Yang Melihat Iklan";
$table = "Ad Impression";
$demo = getRow($resultsAD, $table, $th1, $th2);
print $demo;
	   


?>
</div>

<div class = "row" >
 <?php

$CLParams = array(
      'dimensions' => 'ga:adGroup',
      
      
		);
$resultsCL = $analytics->data_ga->get(
       'ga:' . $profileId,
       '2014-12-06',
       '2014-12-21',
	   'ga:adClicks',
       $CLParams
	   );
	   
$th1 = "Nama Grup Iklan";
$th2 = "Jumlah Audience Yang Melakukan Klik Terhadap Iklan";
$table = "Ad Impression";
$demo = getRow($resultsCL, $table, $th1, $th2);
print $demo;
?> 
</div>

<div class = "row" >
<?php

$CTRParams = array(
      'dimensions' => 'ga:adGroup',
      
      
		);
$resultsCTR = $analytics->data_ga->get(
       'ga:' . $profileId,
       '2014-12-06',
       '2014-12-21',
	   'ga:CTR',
       $CTRParams
	   );
	   
$th1 = "Nama Grup Iklan";
$th2 = "Persentase Orang Yang Melakukan Klik Terhadap Orang Yang Melihat Iklan";
$table = "Click_Through Rate";
$demo = getRow($resultsCTR, $table, $th1, $th2);
print $demo;
?>
</div>

 <div class = "row" >
 <?php



$PVParams = array(
      'dimensions' => 'ga:dimension1',
      
      
     );
$resultsPV = $analytics->data_ga->get(
       'ga:' . $profileId,
       '2014-12-06',
       '2014-12-27',
	   'ga:sessions',
       $PVParams
	   );
	   
function getRowww($results, $table, $th1, $th2, $th3) {
$table;

$conn = mysql_connect('localhost', 'root', '');
if (!$conn) {
    die('Could not connect: ' . mysql_error());
}
echo 'Connected successfully';

mysql_select_db('ta', $conn);

if (count($results->getRows()) > 0) {
  $table .= '<table border="1" cellspacing="1" cellpadding="5">';


  $table .= '<tr>';

	$table .= '<th>'.$th1.'</th>';
	$table .= '<th>'.$th2.'</th>';
	$table .= '<th>'.$th3.'</th>';

  $table .= '</tr>';
  foreach ($results->getRows() as $row) {
 
	$table .= '<tr>';
	$table .= '<td align="left">'.$row[0].'</td>';
	$table .= '<td align="right">'.$row[1].'</td>';
	$sql = 'SELECT username FROM users where idaudience ="'.$row[0].'"';
	$resultquery = mysql_query($sql, $conn);
	
		//$table .= '<td align="right">Audience Tidak Approve</td>';


		while($nama = mysql_fetch_array($resultquery)) {
		//$namaaudience = $nama['username'];
		$table .= '<td align="right">'.$nama['username'].'</td>';
		/* if($nama['username']){
		$namaaudience = "Audience Tidak Approve";	
		}
		else {
			
		} */
		
		
		}
	

	
	$table .= '</tr>';
  }
  $table .= '</table>';

} else {
  $table .= '<p>No results found.</p>';
}

    return $table;
  }
  
$th1 = "IDAudience";
$th2 = "Pageview";
$th3 = "nama";
$table = "PageImpressionAudience";
$demo = getRowww($resultsPV, $table, $th1, $th2, $th3);
print $demo;

/* $table.='Coba';

if (count($resultsPV->getRows()) > 0) {
  $table .= '<table border="1" cellspacing="1" cellpadding="5">';


  $table .= '<tr>';

	$table .= '<th>ID Audience</th>';
	$table .= '<th>PageView</th>';
	$table .= '<th>Nama</th>';

  $table .= '</tr>';
  foreach ($resultsPV->getRows() as $row) {
 
	$table .= '<tr>';
	$table .= '<td align="left">'.$row[0].'</td>';
	$table .= '<td align="right">'.$row[1].'</td>';
	$sql = 'SELECT username FROM users where idaudience ="'.$row[0].'"';
	$result = mysql_query($sql, $conn);
	$table .= '<td align="right">'.$result.'</td>';
					
	$table .= '</tr>';
  }
  $table .= '</table>';

} else {
  $table .= '<p>No results found.</p>';
}

print table; */





/* if (count($resultsAP->getRows()) > 0) {
      
	foreach ($resultsAP->getRows() as $AP)
      {
		$sql = 'SELECT username FROM users where idaudience ="'.$AP[0].'"';
		
		$result = mysql_query($sql, $conn);
		if (!$result) {
		echo "DB Error, could not query the database\n";
		echo 'MySQL Error: ' . mysql_error();
		exit;
}

		while ($row = mysql_fetch_assoc($result)) {
		echo $row['idaudience'];
}
		
		
    
      }
    

    } else {
      echo '<p>No results found.</p>';
    }

mysql_close($conn); */
	   


?> 
</div>


